package com.wisezone.permission.web;

import java.io.Serializable;
import java.util.Collection;

import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.exception.WzWebException;
import com.wisezone.common.utils.BeanUtils;
import com.wisezone.common.utils.ConstantUtils;
import com.wisezone.common.web.BaseController;
import com.wisezone.permission.bean.entity.WzPositionEntity;
import com.wisezone.permission.bean.search.WzPositionSearch;
import com.wisezone.permission.service.WzPositionService;

/**
 * 
 *职位; InnoDB free: 24576 kB
 * 
 * @author create by create date 2010-07-29 14:44:44 update date 2010-07-29
 *         14:44:44
 * 
 */
@WzWebAnnotation(moduleName = "position")
public class WzPositionController extends
		BaseController<WzPositionEntity, WzPositionSearch> {

	/**
	  *
	  *
	  *
	  */
	private WzPositionService wzPositionService;

	/**
	 * 返回清空条件列表
	 * 
	 * @return
	 * @throws WzWebException
	 */
	public String toList() throws WzWebException {

		searchEntity = new WzPositionSearch();
		pagination = this.wzPositionService.listByPage(searchEntity);
		return LIST;
	}

	/**
	 * 获得列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws WzWebException {

		searchEntity = getSearchEntity();
		pagination = this.wzPositionService.listByPage(searchEntity);
		return LIST;
	}

	/**
	 * 进入新增
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterNew() throws WzWebException {

		if (id != null) {
			entity = this.wzPositionService.findById(id);
			entity.setId(null);
		}
		return NEW_EDIT;
	}

	/**
	 * 进入修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterEdit() throws WzWebException {

		entity = this.wzPositionService.findById(id);
		return NEW_EDIT;
	}

	/**
	 * 进入查看
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterView() throws WzWebException {

		entity = this.wzPositionService.findById(id);
		return VIEW;
	}

	/**
	 * 保存
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws WzWebException {

		entity = getEntity();
		entity.setState(ConstantUtils.STATE_EXIST);
		this.wzPositionService.save(entity);
		return toList();
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String update() throws WzWebException {

		entity = getEntity();
		WzPositionEntity oldEntity = this.wzPositionService.findById(id);
		BeanUtils.copyBean(oldEntity, entity);
		this.wzPositionService.update(oldEntity);
		return toList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws WzWebException {

		Collection<Serializable> idList = getIdList();
		if (idList != null) {
			this.wzPositionService.deleteAll(idList);
		}
		return toList();
	}

	public void setWzPositionService(WzPositionService wzPositionService) {
		this.wzPositionService = wzPositionService;
	}

}